package org.litu.app.controller.system;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.litu.app.entity.system.SysDict;
import org.litu.app.service.ISysDictService;
import org.litu.base.controller.BaseFormController;
import org.litu.base.log.LtLog;
import org.litu.core.base.ApiRes;
import org.litu.core.base.SelectVo;
import org.litu.core.enums.ResultEnum;
import org.litu.core.login.TokenCheck;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 字典功能的控制器
 *
 * @author Administrator
 */
@RestController
@LtLog(module = "字典表")
@RequestMapping("/system/sysDict")
@Api(value = "字典表", tags = {"字典表"}, protocols = "http,https")
public class SysDictController extends BaseFormController<SysDict, ISysDictService> {

    @GetMapping("/listDict")
    @ApiOperation(value = "查询字典类型列表", notes = "查询字典类型列表信息")
    public ApiRes<List<SelectVo>> listDict() {
        try {
            List<SysDict> list = service.listDict();
            List<SelectVo> listDict = new ArrayList<>();
            for (SysDict dict : list) {
                listDict.add(new SelectVo(dict.getDictCode(), dict.getDictName()));
            }

            return ApiRes.ok(listDict);
        } catch (Exception e) {
            logger.warn("字典列表查询中出现异常", e);
            return ApiRes.error(ResultEnum.SearchError);
        }
    }
}